package sort;

import org.junit.Test;

/**
 * 二分查找
 */
public class paixu2 {

    public static int test(){
        int srcArray[] = {1,2,4,5,7,8,9,10,11,12,13,77,88,89,97,98};
        int mid = srcArray.length / 2;
        int key =77;
        if (key == srcArray[mid]) {
            return mid;
        }

        int start = 0;
        int end = srcArray.length - 1;
        while (start <= end) {
            mid = (end - start) / 2 + start;
            if (key < srcArray[mid]) {
                end = mid - 1;
            } else if (key > srcArray[mid]) {
                start = mid + 1;
            } else {
                return mid;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        int sd= paixu2.test();
        System.out.println(sd);
    }
}
